package com.example.listener;

import com.example.service.MinioService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * MinIO初始化监听器
 * 在应用启动时初始化MinIO桶
 */
@Slf4j
@Component
public class MinioInitListener implements ApplicationRunner {

    @Autowired
    private MinioService minioService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        try {
            log.info("开始初始化MinIO...");
            minioService.ensureBucketExists();
            log.info("MinIO初始化完成");
        } catch (Exception e) {
            log.error("MinIO初始化失败，请检查MinIO服务器连接和配置", e);
            // 不抛出异常，避免影响应用启动
        }
    }
} 